<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
		<meta charset="UTF-8">
		<title></title>
<link rel="stylesheet" href="/wk2un10/houtai/lib/layui/css/layui.css">
   
	</head>
	<body>
		<form class="layui-form">
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> ID</label>
				<div class="layui-input-inline">
					<input type="text" name="id" id="id"  required lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>图片显示</label>
				<div class="layui-input-inline">
					<input type="text" name="imgUrl" id="imgUrl" required lay-verify="required" autocomplete="off" class="layui-input">
				</div>
				<button type="button" class="layui-btn" id="test1">
  					<i class="layui-icon">&#xe67c;</i>上传图片
				</button>
				<div>
				<img id="imgFace" style="width:120px" src/>
				</div>
			</div>
			<div class="layui-form-item">
   					 <label class="layui-form-label">
   					 <span style="color: red;">*</span>系列型</label>
    				<div class="layui-input-inline">
      					<select name="productId" lay-verify="required">
      					<c:forEach items="${u}" var="u">
       						<option value="${u.id}"> ${u.productTypeName}</option>
        					
        				</c:forEach>
      					</select>
    				</div>
  			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
		<script type="text/javascript" src="/wk2un10/houtai/lib/layui/layui.all.js"></script>
		<script type="text/javascript" src="/wk2un10/houtai/lib/layui/layui.js"></script>
			<script>
	
	layui.use(['form','upload'], function() {
		var form = layui.form;
		var $ = layui.jquery;
		var upload = layui.upload;
		
		 var uploadInst = upload.render({
			    elem: '#test1'
			    ,url: '/wk2un10/PictureSqlServlet?method=upload'
			    ,done: function(res){
			     
			      console.log(res);
			      $("#imgUrl").val('/upload/'+res.data)
			      $("#imgFace").attr('src','/wk2un10/upload/'+res.data)
			    }
			    ,error: function(){
			      
			    }
			  });
		form.on('submit(formDemo)', function(data) {
			var d = data.field; 
			
			d.method="update";
			
			var url ='/wk2un10/PictureSqlServlet';
			
			$.post(url, d,
				function(data) {
					if(data.count>0){
						console.log('添加成功');
						var index=parent.layer.getFrameIndex(window.name); 
     					 parent.layer.close(index);		
					}
				}, "json");
			return false;
		});
	});
	</script>
	</body>
</html>

